package managers 
{
	import flash.net.SharedObject;
	import vo.MapObjectVO;
	/**
	 * ...
	 * @author lgyu
	 */
	public class DDataManager 
	{
		private var _so:SharedObject = null
		public function DDataManager() 
		{
			
		}
		
		public function getMapBGId():int
		{
			return _so.data["mapInfo"]["mapBgId"]
		}
		
		public function getMOList():Array
		{
			var formatedData:Array=[]
			var moList:Array = _so.data["mapInfo"]["mapObjects"]
			for (var i:int = 0; i < moList.length ; i++ ) {
				var obj:Object = moList[i] 
				var mo:MapObjectVO = MapObjectVO.toMVO(obj)
				formatedData.push(mo)
			}
			
			return formatedData;
		}
		
		public function set so(value:SharedObject):void 
		{
			_so = value;
			
			//initSo()
			if (_so.data["inited"] == null) initSo()
			//else trace("_so.date:" + _so.data["inited"])
		}
		private function initSo():void 
		{
			
			_so.data["inited"] = "inited"
			_so.data["mapInfo"] = { }
			
			_so.data.mapInfo["mapBgId"] = 100001
			var mo1:MapObjectVO = new MapObjectVO
			mo1.itemId = 1
			mo1.typeId = 200001
			mo1.positionX = 0
			mo1.positionY = 0;
			
			var mo2:MapObjectVO = new MapObjectVO
			mo2.itemId = 2
			mo2.typeId = 200002
			mo2.positionX = 1
			mo2.positionY = 0
			
			var mo3:MapObjectVO = new MapObjectVO
			mo3.itemId = 3
			mo3.typeId = 200003
			mo3.positionX = 3
			mo3.positionY = 0
			
			var mo4:MapObjectVO = new MapObjectVO
			mo4.itemId = 4
			mo4.typeId = 200004
			mo4.positionX = 0
			mo4.positionY = 6
			
			var mo5:MapObjectVO = new MapObjectVO
			mo5.itemId = 5
			mo5.typeId = 200005
			mo5.positionX = 6
			mo5.positionY = 7
			
			_so.data["mapInfo"]["mapObjects"] = []
			_so.data["mapInfo"]["mapObjects"] = [mo1, mo2, mo3, mo4, mo5]
			
			//trace(_so.data["mapInfo"]["mapObjects"][0] as MapObjectVO)
			
			_so.flush()
		}
		
	}

}